package com.rainy.sso.server.config;

import com.rainy.sso.server.filter.SsoFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;

/**
 * @author liuqin on 2017/12/23
 */
public class FilterConfiguration{

    @Bean
    public FilterRegistrationBean filterDemo4Registration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        //注入过滤器
        registration.setFilter(getSsoFilter());
        //拦截规则
        registration.addUrlPatterns("/*");
        //过滤器名称
        registration.setName("ssoFilter");
        //过滤器顺序
        registration.setOrder(1);
        return registration;
    }

    /**
     * 创建一个bean
     */
    @Bean(name = "ssoFilter")
    public Filter getSsoFilter() {
        return new SsoFilter();
    }
}
